@model HDLogCenter.Infrastructure.Models.AlertRuleModel
@{
    ViewData["Title"] = "创建警告规则";
    var projects = ViewBag.Projects as List<HDLogCenter.Infrastructure.Models.AppConfigModel>;
}

<div class="layui-card">
    <div class="layui-card-header">
        <h2>创建警告规则</h2>
        <div class="layui-btn-group">
            <a href="/AlertConfig" class="layui-btn layui-btn-sm layui-btn-primary">
                <i class="layui-icon layui-icon-return"></i> 返回列表
            </a>
        </div>
    </div>
    <div class="layui-card-body">
        <form class="layui-form layui-form-pane" asp-action="Create" method="post">
            <div class="layui-form-item">
                <label class="layui-form-label">项目 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select asp-for="ProjectCode" lay-verify="required">
                        <option value="">请选择项目</option>
                        @if (projects != null)
                        {
                            @foreach (var project in projects)
                            {
                                <option value="@project.AppCode" selected="@(Model.ProjectCode == project.AppCode)">@project.AppName (@project.AppCode)</option>
                            }
                        }
                    </select>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">日志级别 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select asp-for="LogLevel" lay-verify="required">
                        <option value="">请选择日志级别</option>
                        <option value="1">Error (1)</option>
                        <option value="2">Warning (2)</option>
                        <option value="3">Information (3)</option>
                        <option value="4">Debug (4)</option>
                    </select>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">阈值次数 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input type="number" asp-for="ThresholdCount" placeholder="例如：5" class="layui-input" lay-verify="required|number" min="1" />
                    <div class="layui-form-mid layui-word-aux">在指定时间窗口内达到此次数时触发报警</div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">时间窗口(分钟) <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input type="number" asp-for="TimeWindow" placeholder="例如：1" class="layui-input" lay-verify="required|number" min="1" />
                    <div class="layui-form-mid layui-word-aux">统计错误日志的时间窗口，单位：分钟</div>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">通知类型 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <select asp-for="NotifyType" lay-verify="required">
                        <option value="">请选择通知类型</option>
                        <option value="dingtalk">钉钉</option>
                        <option value="email">邮件</option>
                        <option value="sms">短信</option>
                    </select>
                </div>
            </div>
            
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block">
                    <input type="radio" name="IsEnabled" value="1" title="启用" checked />
                    <input type="radio" name="IsEnabled" value="0" title="禁用" />
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="submitBtn">创建规则</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>

@section Scripts {
    <script>
        layui.use(['form'], function(){
            var form = layui.form;
            
            // 表单验证
            form.verify({
                number: function(value, item){
                    if(value && isNaN(value)){
                        return '请输入有效的数字';
                    }
                }
            });
            
            // 表单提交
            form.on('submit(submitBtn)', function(data){
                // 表单验证通过，可以提交
                return true;
            });
        });
    </script>
}
